package com.leyou.item.web;

import com.leyou.item.entity.Item;
import com.leyou.item.service.ItemService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping("item")
public class ItemController {

    @Resource
    private ItemService itemService;
    /**
     * ResponseEntity是一个Spring提供的，用于封装响应结果的实体类。可以自定义响应状态码、响应头、响应头
     *
     */

    @PostMapping
    public ResponseEntity<Item> saveItem(Item item){
            Item result = itemService.saveItem(item);
            // 新增成功, 返回201
            return ResponseEntity.status(HttpStatus.CREATED).body(result);
    }
}